package com.city.parking.util;

import org.json.JSONObject;

public class HttpResult {
	public String msg;
	public int status;
	public String body;
	public int id;
	private static final String MSG_KEY = "message";
	private static final String STATS_KEY = "status";
	private static final String BODY_KEY = "body";
	private static final String ID_KEY = "Id";
	public static final int STATUS_SUCCESS = 1001;
	public static final int STATUS_FAILED = 1002;
	public static final int STATUS_EXISTS = 1003;

	public static HttpResult fromJson(String str) {
		try {
			JSONObject json = new JSONObject(str);
			HttpResult ret = new HttpResult();
			if (json.has(MSG_KEY))
				ret.msg = json.getString(MSG_KEY);
			if (json.has(STATS_KEY))
				ret.status = json.getInt(STATS_KEY);
			if (json.has(BODY_KEY))
				ret.body = json.getString(BODY_KEY);
			if (json.has(ID_KEY))
				ret.id = json.getInt(ID_KEY);
			return ret;
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		return null;
	}
}
